package com.xixibaby.core;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author tomj
 *
 */
public interface SuperService
                <PO extends SuperPO,
                RESPONSE extends SuperResponse,
                REQUEST extends SuperRequest>
        extends IService<PO> {


    RESPONSE removeById(REQUEST request);
    RESPONSE removeById(REQUEST request, Consumer<REQUEST> valid);

    RESPONSE insert(REQUEST request);
    RESPONSE insert(REQUEST request,Consumer<REQUEST> valid);
    RESPONSE insert(REQUEST request, Consumer<REQUEST> valid, Function<PO,RESPONSE> converter);
    RESPONSE insert(REQUEST request, Function<PO,RESPONSE> converter);

    RESPONSE updateById(REQUEST request);
    RESPONSE updateById(REQUEST request,Consumer<REQUEST> valid);

    IPage<RESPONSE> pageList(REQUEST request);

    /**
     * TODO  需要绕开Function重载的扣子
     * 暂时采用条件构造器在前面  与afterPagelist 区分开来。
     */
    IPage<RESPONSE> pageList(Function<REQUEST,Wrapper<PO>> function,REQUEST request);

    <T extends SuperResponse> IPage<T> pageList(REQUEST request, Function<PO,T> afterPageList);

    <T extends SuperResponse> IPage<T> pageList(REQUEST request, Function<PO, T> after,Function<REQUEST,Wrapper<PO>> function);

    List<RESPONSE> list(REQUEST request);

    RESPONSE selectById(REQUEST request);

    <T extends SuperResponse> T selectById(Long id, Function<PO, T> afterSelect, boolean throwExp);

    <T extends SuperResponse> T selectById(REQUEST request, Function<PO,T> afterSelect);


    /****** 查询辅助方法 *******/

    RESPONSE selectById(Long id);

    RESPONSE selectById(Long id, boolean throwExp);

    <T extends SuperResponse> T selectById(Long id, Function<PO,T> afterSelect);

    RESPONSE selectOneByPro(String proName,Object value);

    RESPONSE selectOneByPro(SFunction<PO,Object> proName, Object value);

    PO selectOnePo(List<String> proName, Object... value);

    PO selectOnePo(String proName, Object value);

    PO selectOnePo(SFunction<PO,Object> proName, Object value);


}
